package com.demoReflect;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class test2Method {
    public static void main(String[] args) throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
        Class c1 =Student.class;

        Method[] methods = c1.getDeclaredMethods();
        for(Method method : methods) {
            System.out.println(method.getName());
        }

        Method eat = c1.getDeclaredMethod("eat",String.class);
        System.out.println(eat.getName()
            + " " + eat.getParameterTypes()
            + " " + eat.getParameterCount()
        );
        //方法invoke实例
        Method run = c1.getDeclaredMethod("run");
        Student stu=new Student();
        Object rs = run.invoke(stu);
        System.out.println(rs);

        String rs2 = (String) eat.invoke(stu,"汉堡包");
        System.out.println(rs2);
    }
}
